//
//  TestUILabelViewController.m
//  iOSDeme
//
//  Created by wxf on 2024/8/25.
//

#import "TestUILabelViewController.h"

@interface TestUILabelViewController ()



@end

@implementation TestUILabelViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    NSLog(@"TestUILabelViewController viewDidLoad");
    self.view.backgroundColor = [UIColor whiteColor];
    
//    [self testBase];
//    [self testUi1];
    [self testUi2];
}

-(void)testBase {
    
    UILabel *uiLabel = [[UILabel alloc]initWithFrame: CGRectMake(0, 100, 200, 40)];
    uiLabel.backgroundColor = [UIColor grayColor];
    uiLabel.text = @"只读文本-UILabel";
    [self.view addSubview:uiLabel];
    
    UILabel *uiLabel1 = [[UILabel alloc]initWithFrame: CGRectMake(0, 150, 200, 40)];
    uiLabel1.backgroundColor = [UIColor grayColor];
    uiLabel1.text = @"只读文本-UILabel";
    //字体大小
    uiLabel1.font = [UIFont systemFontOfSize:22];
    [self.view addSubview:uiLabel1];
    
    UILabel *uiLabel2 = [[UILabel alloc]initWithFrame: CGRectMake(0, 200, 200, 40)];
    uiLabel2.backgroundColor = [UIColor grayColor];
    uiLabel2.text = @"只读文本-UILabel";
    //字体加粗
    uiLabel2.font = [UIFont boldSystemFontOfSize:22];
    //文字颜色
    uiLabel2.textColor = [UIColor redColor];
    [self.view addSubview:uiLabel2];
    
    UILabel *uiLabel3 = [[UILabel alloc]initWithFrame: CGRectMake(0, 250, 200, 40)];
    uiLabel3.backgroundColor = [UIColor grayColor];
    uiLabel3.text = @"UILabel";
    //对齐方式
    //uiLabel3.textAlignment = NSTextAlignmentCenter;
    uiLabel3.textAlignment = NSTextAlignmentLeft;
    //uiLabel3.textAlignment = NSTextAlignmentRight;
    //隐藏-展示
    //uiLabel3.hidden = YES;
    //uiLabel3.hidden = NO;
    //用于查找
    uiLabel3.tag = 1000;
    
    //阴影
    uiLabel3.shadowColor = [UIColor cyanColor];
    //阴影偏移
    uiLabel3.shadowOffset = CGSizeMake(10, 10);
    uiLabel3.shadowOffset = CGSizeMake(5, 5);
    uiLabel3.shadowOffset = CGSizeMake(-5, -5);
    uiLabel3.shadowOffset = CGSizeMake(1, 1);
    uiLabel3.shadowOffset = CGSizeMake(1, 5);
    [self.view addSubview:uiLabel3];
    
    
    UILabel *uiLabel4 = [[UILabel alloc]initWithFrame: CGRectMake(0, 300, 200, 40)];
    uiLabel4.backgroundColor = [UIColor grayColor];
    uiLabel4.text = @"只读文本-UILabel只读文本-UILabel只读文本-UILabel只读文本-UILabel";
    [self.view addSubview:uiLabel4];
    
    UILabel *uiLabel5 = [[UILabel alloc]initWithFrame: CGRectMake(0, 350, 200, 80)];
    uiLabel5.backgroundColor = [UIColor grayColor];
    uiLabel5.text = @"numberOfLines = 0只读文本-UILabel只读文本-UILabel只读文本-UILabel只读文本-UILabel";
    //为0时，自动换行
    uiLabel5.numberOfLines = 0;
    [self.view addSubview:uiLabel5];
    
    UILabel *uiLabel6 = [[UILabel alloc]initWithFrame: CGRectMake(0, 450, 200, 80)];
    uiLabel6.backgroundColor = [UIColor grayColor];
    uiLabel6.text = @"adjustsFontSizeToFitWidth = yes 只读文本-UILabel只读文本-UILabel只读文本-UILabel只读文本-UILabel";
    //uiLabel5.numberOfLines = 0;
    //自调节宽度根据宽度
    //uiLabel6.adjustsFontSizeToFitWidth = YES;
    [uiLabel6 sizeToFit];
    [self.view addSubview:uiLabel6];
}

//象棋
- (void)testUi1 {
    CGFloat w = self.view.frame.size.width / 8;
    //CGFloat h = window.frame.size.height;
    
    NSArray *array = @[@"车",@"马",@"象",@"士",@"王",@"象",@"马",@"车"];
    
    for(int i = 0; i < array.count ; i ++){
        
        for(int j = 0; j < array.count ; j ++){
            
            
            UILabel *uiLabel = [[UILabel alloc]initWithFrame: CGRectMake(j * w, 100 + i * w, w, w)];
            
            //uiLabel.text = i;
            if (i % 2 == j % 2) {
                uiLabel.backgroundColor = [UIColor whiteColor];
            }else {
                uiLabel.backgroundColor = [UIColor blackColor];
            }
            
            uiLabel.textAlignment = NSTextAlignmentCenter;
            uiLabel.textColor = [UIColor redColor];
            
            NSString *v = [NSString stringWithFormat:@"%d", i*8 + j+1];
            uiLabel.text = v;
            [self.view addSubview:uiLabel];
            
        }
    }
}

//象棋 - 棋盘
- (void)testUi2 {
    CGFloat w = self.view.frame.size.width / 9;
    //屏幕高
    //CGFloat h = window.frame.size.height;
    
    NSArray *array = @[@"车",@"马",@"象",@"士",@"王",@"士",@"象",@"马",@"车"];
    
    for(int i = 0; i < array.count ; i ++){
        
        for(int j = 0; j < array.count ; j ++){
            
            
            UILabel *uiLabel = [[UILabel alloc]initWithFrame: CGRectMake(j * w, 100 + i * w, w, w)];
            
            //uiLabel.text = i;
            if (i % 2 == j % 2) {
                uiLabel.backgroundColor = [UIColor whiteColor];
            }else {
                uiLabel.backgroundColor = [UIColor blackColor];
            }
            
            
//            NSString *v = [NSString stringWithFormat:@"%d", i*9 + j+1];
//            uiLabel.text = v;
            if (i == 0 || i == 8) {
                uiLabel.text = array[j];
            }
            
            if (i == 1 || i == 7) {
                uiLabel.text = @"兵";
            }
            
            if(i==0 || i ==1){
                uiLabel.textColor = [UIColor redColor];
            }
            
            if(i==7 || i == 8){
                uiLabel.textColor = [UIColor greenColor];
            }
            
            uiLabel.textAlignment = NSTextAlignmentCenter;
            uiLabel.font = [UIFont boldSystemFontOfSize:20];
            
            [self.view addSubview:uiLabel];
            
        }
    }
}
@end
